Skip to content

feat(opencode): SQLite memory parser + install-gate plugin (verified against opencode-ai@1.17.x) - #156

Merged
sandstream merged 1 commit into
mainfrom
feat/opencode-sqlite-and-gate
Jun 27, 2026
Merged

sandstream merged 1 commit into
mainfrom
feat/opencode-sqlite-and-gate

Conversation

@sandstream

Copy link
Copy Markdown
Owner

What

Closes the live-verification gaps that #117 and #146 explicitly deferred — by installing real OpenCode (opencode-ai@1.17.11) and verifying against the binary, not docs.

1. Memory parser → SQLite (#117)

Current OpenCode stores sessions in SQLite (~/.local/share/opencode/opencode.db), not the legacy flat-JSON storage/ tree our parser assumed — the data dir no longer contains storage/ at all. Confirmed via opencode db path + a sqlite_master schema dump.

  • Adds a SQLite path that reads opencode.db read-only: session.directory = cwd, role from the message.data JSON blob, text from type:"text" part.data blobs.
  • Prefers SQLite; falls back to flat-JSON for older installs. Shared store-writer for both paths; stable opencode:<sessionID>:<messageID> uuid keeps it idempotent.
  • Verified: all three SELECTs run clean against the real full-schema DB (0-row, no error); unit-tested against a synthetic DB built with the verified schema.

2. Install-gate → OpenCode plugin (#146)

OpenCode enforces via a JS plugin, not a config-file hook. Adds installInstallGateOpenCode, which generates .opencode/plugin/kit-install-gate.js:

  • Hooks tool.execute.before (the verified @opencode-ai/plugin contract) and throws to block.
  • For a bash tool call it pipes {tool_input:{command}} into kit gate-bash; non-zero exit (2 = deny) → throw → tool denied.
  • Verified end-to-end against the real binary: OpenCode discovers + loads the generated plugin (appears in resolved-config plugin_origins, no load error); gate-bash passes benign commands (exit 0) and exits 2 on an untriaged install.

Wired into installAllInstallGates. README agent-support matrix + agent-config footer corrected: the blocking gate is shipped for Claude Code / Codex / Amazon Q / Gemini CLI / Cursor (exit-2 hooks) + OpenCode (plugin); Cline (JSON-cancel) and Continue (unverified) remain in #146.

Honest limitation

The final "throw actually denies the tool" step rests on the documented tool.execute.before contract — driving an LLM session to fire a real bash tool call needs an API key, unavailable in the sandbox. Every other link is verified against the running binary.

Dogfooding

Triaged before install per kit's own rule: opencode-ai 88/100, @opencode-ai/plugin 100/100 — both TRIAGE PASSED.

Test plan

  • npm run build clean
  • npm run format:check clean
  • npm test — 1852/0 (5 new: 2 SQLite-memory + 3 OpenCode-gate, incl. one that imports the generated plugin and invokes the hook)
  • parser run against the real opencode.db → clean empty result
  • OpenCode boots and loads the generated plugin (debug logs)
  • gate-bash exit 0 (benign) / exit 2 (untriaged install) via the plugin's payload shape

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

…against opencode-ai@1.17.x)

Verified both surfaces against a real OpenCode install (opencode-ai@1.17.11),
not docs — closes the live-verification gaps in #117 and #146.

memory (#117): current OpenCode stores sessions in SQLite (opencode.db), not
the legacy flat-JSON storage/ tree our parser assumed — confirmed via
`opencode db path` + schema dump; the data dir no longer contains storage/ at
all. Add a SQLite path that reads opencode.db read-only (session.directory =
cwd; role from message.data JSON; text from part.data JSON), preferring it and
falling back to flat-JSON for older installs. Shared store-writer for both.
Verified: queries run clean against the real full-schema DB; unit-tested
against a synthetic DB built with the verified schema.

gate (#146): add installInstallGateOpenCode — OpenCode enforces via a JS
plugin, not a config hook. Generate .opencode/plugin/kit-install-gate.js that
hooks tool.execute.before (verified @opencode-ai/plugin contract) and throws to
block, piping the bash command into `kit gate-bash`. Verified end-to-end:
OpenCode loads the generated plugin (appears in resolved config plugin_origins);
gate-bash parses the {tool_input:{command}} payload, passes benign commands and
exits 2 on an untriaged install (→ plugin throws → tool denied). Wired into
installAllInstallGates; README agent matrix + agent-config footer updated to
reflect the now-shipped gate for Claude Code/Codex/Amazon Q/Gemini/Cursor (hook)
+ OpenCode (plugin), with Cline/Continue still tracked in #146.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants